package com.yuandengta.yomall.product.web;

import com.yuandengta.yomall.product.service.SkuInfoService;
import com.yuandengta.yomall.product.vo.SkuItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * 商品详情页 {@link ItemController}
 *
 * @author Kevin
 * @email: 178676392@qq.com
 */
@Controller
public class ItemController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * sku详情页
     * @param skuId
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String item(@PathVariable("skuId") Long skuId, Model model) {
        try {
            SkuItemVO skuItemVO = skuInfoService.item(skuId);
            model.addAttribute("skuItemVO", skuItemVO);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 创建静态页面
        skuInfoService.createHtml(skuId);

        return "item";
    }
}
